package cn.topevery.garden.dal.logic;

import cn.topevery.garden.dal.dao.PlanDao;
import cn.topevery.garden.dal.util.DeptUtil;
import cn.topevery.garden.entity.dto.ScheduleDTO;
import cn.topevery.garden.entity.po.Plan;
import cn.topevery.garden.entity.query.PlanQuery;
import cn.topevery.garden.entity.vo.PestAnalyzeVO;
import cn.topevery.garden.entity.vo.PlanVO;
import cn.topevery.garden.framework.base.BaseLogic;
import hw.topevery.basis.entity.po.SysUser;
import hw.topevery.framework.db.base.BaseEntityDao;
import hw.topevery.framework.db.entity.DataPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author code-generate
 * @date 2022-01-05
 */
@Service
public class PlanLogic extends BaseLogic<Plan> {
    @Autowired
    PlanDao planDao;

    @Override
    public BaseEntityDao<Plan, Integer> getDao() {
        return planDao;
    }


    /**
     * 获取列表
     *
     * @param query
     */
    public DataPager<PlanVO> listPage(PlanQuery query) {
        return planDao.listPage(query);
    }

    /**
     * 根据自增id批量删除
     *
     * @param ids
     */
    public void deleteBatchById(String userId, Integer[] ids) {
        planDao.delete(userId, ids);
    }

    /**
     * 根据自增id保存或者更新
     *
     * @param plan 实体
     */
    public void saveOrUpdate(String userId, Plan plan) {
        planDao.saveOrUpdate(userId, plan);
    }

    /**
     * 根据自定义列值来获取对象
     */
    public Plan getEntityByColumn(String key, String value) {
        return planDao.getEntityByColumn(key, value);
    }

    public void commit(PlanVO vo, String userId) {
        planDao.commit(vo, userId);
    }

    public DataPager<PlanVO> getList(DataPager<PlanVO> page, Map<String, Object> map) {
        return planDao.getList(page, map);
    }

    public void deleteByIds(String planId, String userId) {
        planDao.deleteByIds(planId, userId);
    }

    public List<Plan> getByName(String name) {
        return planDao.getByName(name);
    }

    public PlanVO getGroupByName(String name) {
        return planDao.getGroupByName(name);
    }

    public List<Plan> getPestPlanList() {
        return planDao.getPestPlanList();
    }

    public void mainPlanApprove(String planId, String userId) {
        planDao.mainPlanApprove(planId, userId);
    }

    public boolean mainPlanConfirm(String planId, String userId) {
        return planDao.mainPlanConfirm(planId, userId);
    }

    public void subPlanExecute(PlanVO vo, String userId) {
        planDao.subPlanExecute(vo, userId);
    }

    public List<PestAnalyzeVO> getPestDeptInfo(boolean isSum) {
        return planDao.getPestDeptInfo(isSum);
    }

    public List<PestAnalyzeVO> getPestAreaInfo(boolean isSum) {
        return planDao.getPestAreaInfo(isSum);
    }

    public List<Plan> getScheduleRecord(String uuid, Integer type) {
        return planDao.getScheduleRecord(uuid, type);
    }

    public DataPager<PlanVO> getTreePlanList(PlanQuery query) {
        return planDao.getTreePlanList(query);
    }

    public void updateExecuteDate(ScheduleDTO dto) {
        planDao.updateExecuteDate(dto);
    }

    public Plan getPlanInfo(Integer id) {
        return planDao.getPlanInfo(id);
    }

    public List<Map<String, Object>> planCount() {
        return planDao.planCount();
    }

    @Autowired
    private DeptUtil deptUtil;

    public DataPager<PlanVO> getSendPlanPage(PlanQuery query, SysUser user) {
        List<String> receiveDeptIds = null;
        if (user.userIsAdmin != 1) {
            receiveDeptIds = deptUtil.setAuthDeptList(user);
        }
        return planDao.getSendPlanPage(query, user, receiveDeptIds);
    }
}
